<body>
	<div class="container minh">
		<ol class="breadcrumb">
			<li class="breadcrumb-item">文章管理</li>
			<li class="breadcrumb-item active">文章列表</li>
		</ol>
		<div class="card mb-3">
			<table id="articles" class="table table-striped table-bordered"
				style="width: 100%;">
				<thead>
					<tr>
						<th>标题</th>
						<th>作者</th>
						<th>发布日期</th>
						<th>类别</th>
						<th>来源</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	<script type="text/javascript">
		var url = "vendor/datatables/zh_CN.json";
		$(document)
				.ready(
						function() {
							$('#articles')
									.dataTable(
											{
												"text-align" : 'center',
												"autoWidth" : false,
												"scrollX" : true,
												"language" : {
													url : url
												},
												"ajax" : 'console/articles',
												"processing" : true,
												"serverSide" : true,
												"ordering" : false,
												"columns" : [
														{
															"data" : "title",
															"width" : "20%"
														},
														{
															"data" : "author"
														},
														{
															"data" : "pubDate",
															"render" : function(
																	data, type,
																	row, meta) {
																//时间格式化
																return moment(
																		data)
																		.format(
																				"YYYY-MM-DD");
															}
														},
														{
															"data" : "catagory",
															"render" : function(
																	data, type,
																	row, meta) {
																if ("java" == data) {
																	return data = "JAVA";
																} else if ("database" == data) {
																	return data = "数据库";
																} else if ("python" == data) {
																	return data = "PYTHON";
																} else {
																	return data = "架构技术";
																}
															}
														},
														{
															"data" : "sourceFrom",
															"render" : function(
																	data, type,
																	row, meta) {
																if ("orignal" == data) {
																	return data = "原创";
																} else {
																	return data = "转载";
																}
															}

														},
														{
															"data" : "status",
															"render" : function(
																	data, type,
																	row, meta) {
																if ("publish" == row.status) {
																	return data = "发布";
																} else {
																	return data = "无效";
																}
															}
														},
														{
															"data" : "id",
															"width" : "20%",
															"render" : function(
																	data, type,
																	row, meta) {
																return data = ' <a  id="detailArticle" class="btn btn-info btn-sm" href="javascript:void(0);" data-id='
																		+ data
																		+ '>详情</a>&nbsp;<a id="editArticle" class="btn btn-warning btn-sm" href="#" data-id='+data+'>编辑</a>&nbsp;<a id="freezeArticle" class="btn btn-danger btn-sm" href="#" data-id='+data+'>冻结</a>';
															}
														} ]
											});
						});

		$(document).delegate('#detailArticle', 'click', function() {
			$("#main").load("console/detail/" + $(this).data("id"));
			return false;
		});
	</script>
</body>